package test;

enum LightState {
    ON,
    OFF
}

// 状态机类
class LightStateMachine {
    private LightState currentState;

    public LightStateMachine() {
        currentState = LightState.OFF;
    }

    // 执行操作以切换状态的方法
    public void toggleSwitch() {
        if (currentState == LightState.OFF) {
            currentState = LightState.ON;
            System.out.println("灯已打开。");
        } else {
            currentState = LightState.OFF;
            System.out.println("灯已关闭。");
        }
    }

    // 获取当前状态的方法
    public LightState getCurrentState() {
        return currentState;
    }
}

// 测试状态机的主类
public class test {
    public static void main(String[] args) {
        LightStateMachine light = new LightStateMachine();

        System.out.println("初始状态: " + light.getCurrentState());

        light.toggleSwitch();
        light.toggleSwitch();
    }
}